<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>登录 - 筑为智慧</title>
    <!-- 资 源 引 入 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel='stylesheet' href='/static/component/layui/css/layui.css'>
    <link rel='stylesheet' href='/static/admin/css/other/login.css'>
    <script src='/static/admin/js/server.js'></script>
    <script src='/static/component/layui/layui.js'></script>
    <script src='/static/component/laytp/layuiConfig.js'></script>
    <script language=javascript src='/static/admin/jsencrypt/jsencrypt.js' charset='utf-8'></script>
</head>
<style>
    #chang{width:1200px;height:550px;background:url('/static/admin/images/chang.png');background-size: 100% 100%;
        background-repeat:no-repeat;display: none}
    .loggin_logo{margin:30px 0 0 100px; width: 450px;height: 400px}
    .banquan{margin-left: 115px}
    .lefts{float: left}
    .logintit{margin:60px 0 0 100px;}
    .inptit{margin-left: 5px;margin-top: 30px;font-size: 16px;font-weight: bold}
    .regbut{color: #2272eb;text-align: center;margin-top: 10px;cursor: pointer;position: relative;bottom: -6px;left: 6px;}
</style>
<!-- 代 码 结 构 -->
<body style="background:url('/static/admin/images/background.png');background-size: 100%;background-repeat:no-repeat;">

<div id="chang">
    <div class="lefts">
        <a href="javascript:;"><img class="loggin_logo" src="/static/admin/images/chatu.png"></a>
        <div class="banquan">@2023 <a href="http://www.zhuwe.net" target="_blank">筑为智慧</a> 成都筑为科技有限公司 蜀ICP备18021004号</div>
    </div>
    <div class="lefts">
        <img class="logintit" src="/static/admin/images/logintit.png">
        <form class="layui-form" lay-filter="layui-form" action="javascript:void(0);">
            <div id="logsinfo" >
                <div class="inptit">手机号</div>
                <div class="layui-form-item">
                    <input name="tel" placeholder="请输入登录手机号: " lay-verify="required" lay-reqtext="请输入登录手机号" hover class="layui-input" autocomplete="off"  />
                </div>
                <div class="inptit">密码</div>
                <div class="layui-form-item">
                    <input type="password" name="pass" placeholder="请输入密码:" lay-verify="required" lay-reqtext="请输入登录密码" hover class="layui-input"  />
                </div>
                <div class="layui-form-item login-form-item">
                    <input type="checkbox" name="rem" id="rem" lay-filter="checkbox" value="1" title="记住密码" lay-skin="primary">
                    <input type="checkbox" name="keep" id="keep" lay-filter="checkbox" value="1" title="保持登录" lay-skin="primary">
                    <a href="javascript:void(0)" onclick="get_to_reg()" class="regbut">没有体验账号，点这里注册 >></a>
                </div>
                <div class="layui-form-item login-form-item">
                    <button type="submit" class="laytp-btn laytp-btn-success login operatbut" lay-submit lay-filter="login">
                        登  录
                    </button>

                </div>
            </div>


            <div id="rolesinfo" class="layui-hide">
                <div style="text-align: center">选择本次登录的用户类型</div>
                <div class="list"></div>
                <div class="layui-form-item login-form-item">
                    <button id="roleCancel" type="submit" class="laytp-btn laytp-btn-success" lay-submit lay-filter="rolecancel">取消</button>
                    <button id="roleSub" type="submit" class="laytp-btn laytp-btn-success" lay-submit lay-filter="rolesub">确定</button>
                </div>
            </div>
        </form>
    </div>
</div>
</body>

<script>

    var param_vision = getQueryVariable('vision') || '';
    function get_to_reg(){
        window.location.href = "/reg.php?vision="+param_vision;
    }


    var checkmapcode = true;
    layui.use(['laytp','button'], function() {
        var form = layui.form;
        var $ = layui.$;
        var context = layui.context;

        $("#chang").css('margin-top',(document.documentElement.clientHeight-550)/2);
        $("#chang").css('margin-left',(document.documentElement.clientWidth-1200)/2);
        $("#chang").show();


        // var reminfo = unescape(facade.getCookie('reminfo'));
        var reminfo = facade.getCookie('reminfo');
        if(reminfo) reminfo = JSON.parse(reminfo);
        if(reminfo.tel) $("input[name='tel']").val(reminfo.tel);
        if(reminfo.pass) $("input[name='pass']").val(reminfo.pass);
        if(reminfo.rem) $("#rem").attr('checked','checked');
        if(reminfo.keep) $("#keep").attr('checked','checked');
        form.render("checkbox");


        form.on('submit(login)', function(data) {
            var err_num = get_error_login();
            if(err_num > 2 && checkmapcode){
                layer.open({
                    type: 2,
                    title: '登录验证',
                    area: ['600px', '400px'],
                    maxmin: true,
                    content: '/page/public/mapcode.php'
                });
                return false;
            }

            facade.ajax({url: ask_login, data: getEncryptData(data.field)}).done(function(res){
                if (res['code'] === 2000) {
                    if(res.data.succ == 1){
                        facade.setCookie('pmlock', 0);
                        window.localStorage.removeItem('pminfo');
                        if(data.field.rem){
                            facade.setCookie("reminfo", JSON.stringify(data.field), 7);
                        }else{
                            facade.delCookie("reminfo");
                        }
                        facade.clearCache();
                        facade.setCookie("token", res.data.token, 7);
                        facade.redirect("/index.php");
                    }else{
                        $("#logsinfo").addClass('layui-hide');
                        $("#rolesinfo").removeClass('layui-hide');

                        var rolearr = res.data.rolearr;
                        var str = '';
                        for (var key in rolearr){
                            str += '<div class="li" key="'+rolearr[key].value+'">'+rolearr[key].name+'</div>';
                        }
                        $("#rolesinfo .list").html(str);
                        $("#rolesinfo .list .li").click(function () {
                            $("#rolesinfo .list .li").removeClass('active');
                            $(this).addClass('active');
                        });
                    }
                }else{
                    set_error_login();
                }
            });
            return false;
        });



        form.on('submit(rolecancel)', function(data) {
            $("#logsinfo").removeClass('layui-hide');
            $("#rolesinfo").addClass('layui-hide');
        });

        form.on('submit(rolesub)', function(data) {
            if($("#rolesinfo .list .active").length < 1){
                facade.error('请选择本次登录的用户类型');return false;
            }else{
                var roletype = parseInt($("#rolesinfo .list .active").attr('key'));
            }
            data.field.roletype = roletype;
            facade.ajax({url: ask_loginrole, data: getEncryptData(data.field)}).done(function(res){
                if (res['code'] === 2000) {
                    facade.setCookie('pmlock', 0);
                    window.localStorage.removeItem('pminfo');
                    if(data.field.rem){
                        facade.setCookie("reminfo", JSON.stringify(data.field), 7);
                    }else{
                        facade.delCookie("reminfo");
                    }
                    facade.clearCache();
                    facade.setCookie("token", res.data, 7);
                    facade.redirect("/index.php");
                }else{
                    set_error_login();
                }
            });
            return false;
        });

    });






    function getEncryptData(data) {
        if(!data){
            return {};
        }
        var Obj = {};
        Obj.data = encrypt(JSON.stringify(data));
        return Obj;
    }

    function set_error_login(){
        var old_login_info = window.localStorage.getItem('pminfo');
        old_login_info = JSON.parse(old_login_info);
        if(Object.prototype.toString.call(old_login_info) === '[object Object]' && old_login_info.errdate == get_now_date()){
            window.localStorage.setItem('pminfo',JSON.stringify({errnum:parseInt(old_login_info.errnum)+1, errdate:get_now_date()}));
        }else{
            window.localStorage.setItem('pminfo',JSON.stringify({errnum:1, errdate:get_now_date()}));
        }
    }
    function get_error_login(){
        var login_info = window.localStorage.getItem('pminfo');
        login_info = JSON.parse(login_info);
        if(Object.prototype.toString.call(login_info) === '[object Object]' && login_info.errdate == get_now_date()){
            return parseInt(login_info.errnum);
        }else{
            return 0;
        }
    }
    function get_now_date() {
        var date = new Date();
        return date.toLocaleDateString();
    }

    function getQueryVariable(variable) {
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
        }
        return false;
    }

</script>
<script language="javascript" src="https://put.zoosnet.net/JS/LsJS.aspx?siteid=PUT23492095&float=1&lng=cn"></script>
</html>
